import { defineStore } from 'pinia'
import { ISession } from '@/types/auth'
import { loginAdminApi } from '@/apis/session'
import { ElMessage } from 'element-plus'

export const useAuthStore = defineStore('auth', {
  state: () => ({
    loginForm: {
      username: '',
      password: '',
      isRemember: false
    },
    loginLoading: false,
    isVerified: false,
    session: {} as ISession
  }),
  actions: {
    async handleLogin() {
      const { username, password } = this.loginForm
      this.session = await loginAdminApi(username, password)
      ElMessage.success('登录成功')
    },
    resetLoginForm() {
      this.loginForm = {
        username: '',
        password: '',
        isRemember: false
      }
    }
  }
})
